#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "uthash.h"

bool exist(char** board, int boardSize, int* boardColSize, char* word);
bool dfs(int, int, char**, char*);

int main()
{
	return 0;
}

int colLen, rowLen;
bool exist(char** board, int boardSize, int* boardColSize, char* word)
{
	rowLen = boardSize; colLen = *boardColSize;
	char ch = word[0];
	if (!ch) return true;

	for (int row = 0; row < boardSize; row++)
		for (int col = 0, len = *boardColSize; col < len; col++)
			if (ch == board[row][col] && dfs(row, col, board, word)) return true;

	return false;
}

bool dfs(int row, int col, char** board, char* word)
{
	char ch = word[0];
	if (!ch) return true;
	if (row < 0 || col < 0 || row == rowLen || col == colLen || ch != board[row][col])
		return false;

	board[row][col] = '.';
	bool res =
		dfs(row + 1, col, board, word + 1) ||
		dfs(row - 1, col, board, word + 1) ||
		dfs(row, col + 1, board, word + 1) ||
		dfs(row, col - 1, board, word + 1);

	board[row][col] = ch;
	return res;
}
